//
//  WelcomeViewController.swift
//  weibo1
//
//  Created by 李进 on 15/10/18.
//  Copyright © 2015年 李进. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage

class WelcomeViewController: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
        view = imageview
        setView()
        
       // let url = userAccViewModel.shareAccViewModel.avalurl
        
        iconimageview.sd_setImageWithURL(userAccViewModel.shareAccViewModel.avalurl, placeholderImage: UIImage(named: "avatar_default_big"))
        
    }
    
    
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        //加载完成view以后就实现最后layout的位置
        //添加自动布局
        iconimageview.snp_updateConstraints { (make) -> Void in
           make.bottom.equalTo(view.snp_bottom).offset(-view.bounds.height + 200)
        }
        
        titleLbael.alpha = 0
        //添加动画
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.8, initialSpringVelocity: 5, options: [], animations: { () -> Void in
            //使用这个方法会，会收据所有layout的路径
            
            self.view.layoutIfNeeded()
             self.titleLbael.alpha = 0.7
            
            }) { (_) -> Void in
                
                //创建通知中心
                NSNotificationCenter.defaultCenter().postNotificationName(NotificationCenterName, object: "welcome")
                
        }
    }
    
     
    //懒加载view中的cell
    
    private lazy var imageview:UIImageView = UIImageView(imageName: "ad_background")
    
    private lazy var iconimageview: UIImageView = {
        
        let iv = UIImageView(imageName: "avatar_default_big")
        
        iv.layer.cornerRadius = 45
        
        iv.layer.masksToBounds = true
        
        return iv
    }()
    
    private lazy var titleLbael: UILabel = UILabel(titlt: "欢迎归来", fontsize: 18)
}

extension WelcomeViewController {
    
    func setView(){
        
        view.addSubview(iconimageview)
        view.addSubview(titleLbael)

        //设置自动布局
        iconimageview.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(view.snp_centerX)
            make.bottom.equalTo(view.snp_bottom).offset(-200)
            make.width.equalTo(90)
            make.height.equalTo(90)
        }
        
        titleLbael.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(iconimageview.snp_bottom).offset(16)
            
            make.centerX.equalTo(view.snp_centerX)
        }
    }
}
